package com.geektime.hello;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ArrayDemo {
    public static void main(String[] args) {

        String str = "http://ahtv-obs.obs.cn-north-4.myhuaweicloud.com:80/16027591927866249.mp4,http://ahtv-obs.obs.cn-north-4.myhuaweicloud.com:80/16027591927871634.mp4,http://ahtv-obs.obs.cn-north-4.myhuaweicloud.com:80/16027591927876897.mp4,http://ahtv-obs.obs.cn-north-4.myhuaweicloud.com:80/16027591927871701.mp4,http://ahtv-obs.obs.cn-north-4.myhuaweicloud.com:80/16027591927872317.jpeg,http://ahtv-obs.obs.cn-north-4.myhuaweicloud.com:80/16027591927875161.jpeg";
        String[] arr = str.split(",");
        for (String s : arr) {
            if (s.endsWith(".mp4")) {
                System.out.println(s);
            }
        }

        // https://snailclimb.gitee.io/javaguide/#/docs/java/basis/Java%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E7%96%91%E9%9A%BE%E7%82%B9
        int[] i = {1, 2, 3, 4};
        List list = Arrays.asList(i);
//        list.add(5);
        System.out.println(list.getClass());
        System.out.println("list = " + list);

        Integer[] i2 = {1, 2, 3, 4};
        List list2 = Arrays.asList(i2);
        // 返回的是Arrays里的内部类，很多方法没有
//        list2.add(5);
        System.out.println(list2.getClass());
        System.out.println("list2 = " + list2);

        // 推荐方法
        List list3 = new ArrayList<>(Arrays.asList(1, 2, 3, 4));
        System.out.println(list3.getClass());
        System.out.println("list3 = " + list3);


        List<String> list1 = new ArrayList();
        list1.add("1");
        list1.add("2");
        // 1删除正常，改成2后抛出异常ConcurrentModificationException
        // 用Iterator做循环
        //fail-fast 机制 ：多个线程对 fail-fast 集合进行修改的时，可能会抛出ConcurrentModificationException，单线程下也会出现这种情况
        for (String s : list1) {
            if ("2".equals(s)) {
                list1.remove(s);
            }
        }
        System.out.println("list1 = " + list1);
    }
}
